package com.nightpiter.view.drawer.dynamic;

import com.nightpiter.view.graphics.Canvas;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
class IntermediateBacillus extends Bacillus {

	private Bacillus primaryBacillus, secondaryBacillus;

	public IntermediateBacillus(IntermediateAmoeba intermediateAmoeba,
			Amoeba oddAmoeba, Bacillus primaryBacillus,
			Bacillus secondaryBacillus) {
		this.primaryBacillus = primaryBacillus;
		this.secondaryBacillus = secondaryBacillus;
		// TODO
		assert (primaryBacillus.intermediateBacillus == null);
		primaryBacillus.intermediateBacillus = this;
		secondaryBacillus.intermediateBacillus = this;

		this.evenAmoeba = intermediateAmoeba;
		this.oddAmoeba = oddAmoeba;
		intermediateAmoeba.addNeighbor(oddAmoeba, this);
		oddAmoeba.addNeighbor(intermediateAmoeba, this);

		this.transfersSize = primaryBacillus.transfersSize
				+ secondaryBacillus.transfersSize;
		this.tunnelsSize = primaryBacillus.tunnelsSize
				+ secondaryBacillus.tunnelsSize;

		this.transferParts.addAll(primaryBacillus.transferParts);
		this.tunnelParts.addAll(primaryBacillus.tunnelParts);
		this.transferParts.addAll(secondaryBacillus.transferParts);
		this.tunnelParts.addAll(secondaryBacillus.tunnelParts);

	}

	public IntermediateBacillus(IntermediateAmoeba intermediateAmoeba,
			Amoeba oddAmoeba, Bacillus bacillus) {
		this.primaryBacillus = bacillus;
		// TODO
		assert (bacillus.intermediateBacillus == null);
		bacillus.intermediateBacillus = this;

		this.evenAmoeba = intermediateAmoeba;
		this.oddAmoeba = oddAmoeba;
		intermediateAmoeba.addNeighbor(oddAmoeba, this);
		oddAmoeba.addNeighbor(intermediateAmoeba, this);

		this.transfersSize = bacillus.transfersSize;
		this.tunnelsSize = bacillus.tunnelsSize;

		this.transferParts.addAll(bacillus.transferParts);
		this.tunnelParts.addAll(bacillus.tunnelParts);

	}

	@Override
	protected void draw(Canvas canvas) {
		if (((IntermediateAmoeba) evenAmoeba).getCurrentDistance() > Config.mergeDistance) {
			primaryBacillus.draw(canvas);
			if (secondaryBacillus != null) {
				secondaryBacillus.draw(canvas);
			}
		} else {
			super.draw(canvas);
		}
	}

}
